package com.ymatou.iapi.advancewithdraw.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.advancewithdraw.service.AWAccountCreateCall;
import org.json.JSONObject;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtAWAccountWapper;
/**
*创建提前放款账户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AWAccountCreate{
	private static AWAccountCreateCall awaccountcreateCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建提前放款账户");
	}

	@Before
	public void caseUp() {
		awaccountcreateCall=new AWAccountCreateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(awaccountcreateCall.getOpurl());
	}
		
	public static void  awaccountgetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
		    String dataStr = awaccountcreateCall.getReturnData();
			//返回报文断言			
//			String accountId =  new JSONObject(dataStr).getString("AccountId");
//			Logger.verifyIsNull(accountId, "AccountId为空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_AWAccountCreate_001() {
		Logger.start(true,"创建提前放款账户");
		try {
			//创建提前放款测试账户

			//调用接口
		    Map<String, Object> getMap = new HashMap<String,Object>();			
			JSONObject accountCreate=awaccountcreateCall.callAndGetReturnData(getMap);
			
			//获取返回的报文
			Logger.verifyNotNull(accountCreate, "返回报文非空");
			//断言报文返回true
			String success= accountCreate.getString("Success");
			Logger.verifyIsContains(true, success, "\"Success\":true");
			//断言errorMsg为空
			String errMsg=accountCreate.getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "ErrorMsg等于空");
	
			if(errMsg=="null")
			{
				String awaccountId=accountCreate.getString("AWAccountId");
				//断言AWAccountID非空
				Logger.verifyNotNull(awaccountId, "断言AWAccountID非空");
				
				//SQL ymtfp库  Ymt_AWAccount 
				YmtAWAccountWapper ymtawaccountWapper= new YmtAWAccountWapper();
				String accountId = ymtawaccountWapper.selectBySellerId(3383).getAccountId();
				//验证提前放款账户ID一致
                Logger.verifyEquals(accountId, awaccountId, "提前放款账户ID");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountCreate_002() {
		Logger.start(false,"卖家用户Id不能为空");
		try {
			//TODO 补全case代码
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("SellerId", null);
			awaccountcreateCall.callAndGetReturnData(updateMap);

			awaccountgetreturnerrcode("1001","卖家用户Id不能为空");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountCreate_003() {
		Logger.start(false,"卖家用户登录名不能为空");
		try {
			//TODO 补全case代码
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("SellerLoginId", null);
			awaccountcreateCall.callAndGetReturnData(updateMap);

			awaccountgetreturnerrcode("1001","卖家用户登录名不能为空");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountCreate_004() {
		Logger.start(false,"该买手信用等级不足");
		try {
			//TODO 补全case代码
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("SellerId", 288484);
			updateMap.put("Level", 2);
			awaccountcreateCall.callAndGetReturnData(updateMap);

			awaccountgetreturnerrcode("1012","该买手信用等级不足");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountCreate_005() {
		Logger.start(false,"创建提前放款账户（错误校验，账户已存在）");
		try {
			//TODO 补全case代码
		    Map<String, Object> getMap = new HashMap<String,Object>();			
			awaccountcreateCall.callAndGetReturnData(getMap);
			
			awaccountgetreturnerrcode("1011","该买手已存在提前放款账号");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}